Skip to content

docs: add ADR on JWT usage#34

Merged
mariajgrimaldi merged 1 commit intoopenedx:mainfrom
rodmgwgu:rod/jwt-usage
Sep 10, 2025
Merged

docs: add ADR on JWT usage#34
mariajgrimaldi merged 1 commit intoopenedx:mainfrom
rodmgwgu:rod/jwt-usage

Conversation

@rodmgwgu
Copy link
Copy Markdown
Contributor

@rodmgwgu rodmgwgu commented Sep 2, 2025

Description

This PR adds a proposed ADR on the use of JWT tokens for AuthZ.

The decision on this document is open for discussion, please add any comment or concern on the proposed approach, this was derived based on my research on past and present usage of JWT tokens on the platform and previous efforts for implementing authorization mechanisms.

My knowledge on this part of the platform and it's history is still limited, so please feel free to add any concerns or points that I may not have taken into account.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Sep 2, 2025
@openedx-webhooks
Copy link
Copy Markdown

openedx-webhooks commented Sep 2, 2025

Thanks for the pull request, @rodmgwgu!

This repository is currently maintained by @openedx/committers-openedx-authz.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@mariajgrimaldi
Copy link
Copy Markdown
Member

mariajgrimaldi commented Sep 3, 2025

@sarina @rodmgwgu: can we get the CLA signed? 👀 Not sure how this is working with WGU.

Comment on lines +101 to +103
We will not include AuthZ data in the JWT tokens. JWT tokens will
continue to be used as an authentication mechanism, but AuthZ will be
handled separately in the backend.
Copy link
Copy Markdown
Member

@mariajgrimaldi mariajgrimaldi Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally agree with this approach!

Currently, I can only see those roles being passed currently directly in the JWT payload: https://github.com/openedx/edx-platform/blob/acbf50a7dd8492a9fb80f35ffbc561b668fe619d/openedx/core/djangoapps/oauth_dispatch/jwt.py#L275-L276 for administrator and superuser roles. We haven't decided whether to use those django-native definitions still or move them into the authZ. What makes more sense to me, simplicity-wise, is to keep using those and implement other feature-specifics into the authz system but we'd need a way of integrating them seamlessly. In any case, that would mean continuing to send the same roles in the same format. What do you think?

Copy link
Copy Markdown
Contributor Author

@rodmgwgu rodmgwgu Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the existing roles will continue being passed to the JWT as-is, and for now will still be picked by the current auth code.

The new AuthZ implementation won't directly care about these, unless we find any special case that would need it, in that case we would do an "OR" on the specific action, for example:

Let's say that we identify that superuser should always have access to "read" any Library, on the GET library endpoint handler, we would validate like (pseudo code):

has_access = is_superuser() or new_authz_has_permission("library-read", user, library)

where is_superuser() is the existing code that validates this, and new_authz_has_permission is our new implementation.

Would this make sense?

Copy link
Copy Markdown
Member

@mariajgrimaldi mariajgrimaldi Sep 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that makes total sense. I think this is the simplest approach given the current state.

Another case came to my attention last week while I was discussing with my team about how the new authz framework should interact with other systems: Aspects. Currently, this is how the system manages access to its resources:
https://github.com/openedx/tutor-contrib-aspects/blob/e0db9f51250fd842dcdcce8abb57befc17cff0ae/tutoraspects/templates/aspects/apps/superset/pythonpath/openedx_sso_security_manager.py#L179-L208 - roles are sent in the JWT. It looks like we only use admin and superuser -I think- so it should work the same.

If this is not the case, then we'll need to decide on our next steps for handling this specific case of authorization management, but it's not an immediate blocker. Should we document this somewhere?

FYI @bmtcril

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if the existing JWT implementation doesn't change that is fine for Aspects' use of the superuser role to grant access to all reports.

However in the long term, the way Aspects uses the courses endpoint to find which roles the user has on individual courses will have to change. Ideally we would have an endpoint that would allow us to get all courses that a specific user has a specific permission on instead of having to query all courses that the user is associated with, then do further API calls to determine if they have the necessary permission to view reports for each course.

I'm not sure those details are relevant to this ADR, but we may want to capture the generic use case for "external service needs to check LMS/Studio permissions over API" somewhere.

@rodmgwgu
Copy link
Copy Markdown
Contributor Author

rodmgwgu commented Sep 3, 2025

@sarina @rodmgwgu: can we get the CLA signed? 👀 Not sure how this is working with WGU.

We are working on it now, thanks.

@sarina sarina moved this from Needs Triage to Needs Tests Run or CLA Signed in Contributions Sep 4, 2025
@sarina
Copy link
Copy Markdown
Contributor

sarina commented Sep 8, 2025

Closing to rekick the CLA check

@sarina sarina closed this Sep 8, 2025
@github-project-automation github-project-automation Bot moved this from Needs Tests Run or CLA Signed to Done in Contributions Sep 8, 2025
@sarina sarina reopened this Sep 8, 2025
Copy link
Copy Markdown
Contributor

@sarina sarina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great to me! Requesting a review as well from @bmtcril

@sarina
Copy link
Copy Markdown
Contributor

sarina commented Sep 9, 2025

Closing and re-opening to kick the new status check.

@sarina sarina closed this Sep 9, 2025
@sarina sarina reopened this Sep 9, 2025
@sarina
Copy link
Copy Markdown
Contributor

sarina commented Sep 9, 2025

@mariajgrimaldi could you review and merge when you're ready?

@sarina sarina moved this from Done to In Eng Review in Contributions Sep 9, 2025
@mariajgrimaldi
Copy link
Copy Markdown
Member

@sarina: of course! I added a comment earlier today: #34 (comment). By the way, I don't think I have write permissions yet.

@sarina
Copy link
Copy Markdown
Contributor

sarina commented Sep 9, 2025

@mariajgrimaldi you do now! 🙂

Comment thread docs/decisions/0003-jwt-usage.rst Outdated
Comment thread docs/decisions/0003-jwt-usage.rst Outdated
tokens for Authorization purposes.

Possible Methods
================
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not actually important but the bullets in this section are nested too far and in the rendered view they view as quotes (https://openedx-authz--34.org.readthedocs.build/en/34/decisions/0003-jwt-usage.html#possible-methods). Probably not actually worth fixing, but worth paying attention to for more user-facing documentation.

Copy link
Copy Markdown
Member

@mariajgrimaldi mariajgrimaldi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@mariajgrimaldi mariajgrimaldi merged commit d722867 into openedx:main Sep 10, 2025
14 checks passed
@github-project-automation github-project-automation Bot moved this from In Eng Review to Done in Contributions Sep 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

open-source-contribution PR author is not from Axim or 2U

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants